package biolabs.gui.deploy;

import java.awt.Dimension;
import java.io.PrintStream;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import biolabs.core.Application;
import biolabs.gui.Stage;

public class DesktopApp {

	private static final String title = "BioLabs";
	private static final int initialWidth = 800;
	private static final int initialHeight = 600;

	public static void main(String[] args) {
		JFrame window = new JFrame(title);

		Application app;
		try {
			app = new Application();
		} catch(RuntimeException e) {
			throw e; // TODO display in UI (after splash screen)
		}

		Stage stage = new Stage(app);
		app.getLogger().addHandler(stage.getLogHandler());

		System.out.println("Standard output and standard error redirected to GUI console");
		System.setOut(new PrintStream(stage.getOutputStream()));
		System.setErr(new PrintStream(stage.getErrorStream()));
		window.add(stage.getContent());
		Dimension d = window.getMinimumSize();
		window.setSize(
				Math.max(initialWidth, d.width),
				Math.max(initialHeight, d.height));
		window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		window.setVisible(true);
	}
}
